var DWZ=parent.DWZ;
$(document).ready(function(){	
	getLayout();	
});

var choiceLayouts={};
function getLayout(){
	var url="/demo/layout";
	DWZ.get(url,function(msg){
		var layoutContainer=$("#layoutContainer");
		var templet = $("#templet").html();
		var layouts = msg.result||[];
		$.each(layouts,function(i,layout){
			var row = templet.replace(/\${title}/g,layout.title);
			var container = layout.container;
			var items=[];
			$.each(layout.items,function(j,item){
				items.push(item.templet);
			})
			container=container.replace(/\${container}/,items.join(""));
			row=row.replace(/\${container}/,container);
			
			row=$(row);
			
			$(">div[name=head] input[type=checkbox]",row).click(function(e){
				if(this.checked){
					choiceLayouts["layout_id"+layout.layout_id]={
						data:layout,
						demo:container
					}
					$(this).parents("div[name=head]").parent().css("border","red 1px solid");
				}else{
					delete choiceLayouts["layout_id"+layout.layout_id];
					$(this).parents("div[name=head]").parent().css("border","white 1px solid");
				}
			});//.data("layout",container);
			
			row.appendTo(layoutContainer);
		})
	})
}

/**
 * 执行选择操作
 */
function choice(){
	if(callback)callback(choiceLayouts);
}